package com.jwgf.smarowindingmachine_unity.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jwgf.objectbox.CbfReport;
import com.jwgf.smarowindingmachine_unity.R;
import com.jwgf.smarowindingmachine_unity.logic.MachineParameterSharedPreference;
import com.jwgf.smarowindingmachine_unity.logic.Report;

/**
 * Created by Jacky on 2017/8/18.
 */

public class ProductionCBFView extends LinearLayout {
    private Context context;

    private TextView tv_spinning_cop_number;
    private TextView tv_in_spindle_number;
    private TextView tv_empty_tube_ratio;
    private TextView tv_joint1_pass_number;
    private TextView tv_joint1_succeed_number;
    private TextView tv_joint1_succeed_ratio;
    private TextView tv_pull_tube_pass_number;
    private TextView tv_succeeded_thrum_ratio;

    private TextView tv_remnant_tube_number;
    private TextView tv_empty_tube_number;
    private TextView tv_remnant_tube_ratio;
    private TextView tv_joint2_pass_number;
    private TextView tv_joint2_succeed_number;
    private TextView tv_joint2_succeed_ratio;
    private TextView tv_joint3_pass_number;
    private TextView tv_joint3_succeed_number;
    private TextView tv_joint3_succeed_ratio;
    private TextView tv_second_succeeded_thrum_ratio;


    private TextView tv_succeeded_thrum_number;
    private TextView tv_lost_thrum_number;
    private TextView tv_second_succeeded_thrum_number;
    private TextView tv_second_lost_thrum_number;


    public ProductionCBFView(Context context) {
        super(context);
        this.context = context;
        LayoutInflater.from(context).inflate(R.layout.fragment_production_management_shift_report_cbf, this);
        initViews();

    }

    public void setData(CbfReport shiftData) {
        String machine_type = MachineParameterSharedPreference.getInstance()
                .getValue(MachineParameterSharedPreference.MACHINE_MACHINE_TYPE, "0");
        String spinningin_type = MachineParameterSharedPreference.getInstance()
                .getValue(MachineParameterSharedPreference.MACHINE_SPINNINGIN_TYPE, "0");

        if (machine_type.equals("3")) {
            findViewById(R.id.in_spindle_num_layout).setVisibility(View.GONE);
            findViewById(R.id.joint1_pass_num_layout).setVisibility(View.GONE);
            findViewById(R.id.joint1_succeed_num_layout).setVisibility(View.GONE);
            findViewById(R.id.joint1_succeed_ratio_layout).setVisibility(View.GONE);
            findViewById(R.id.pull_tube_pass_num_layout).setVisibility(View.GONE);
            findViewById(R.id.joint2_pass_num_layout).setVisibility(View.GONE);
            findViewById(R.id.joint2_succeed_num_layout).setVisibility(View.GONE);
            findViewById(R.id.joint2_succeed_ratio_layout).setVisibility(View.GONE);
            findViewById(R.id.joint3_pass_num_layout).setVisibility(View.GONE);
            findViewById(R.id.joint3_succeed_num_layout).setVisibility(View.GONE);
            findViewById(R.id.joint3_succeed_ratio_layout).setVisibility(View.GONE);

            findViewById(R.id.succeeded_thrum_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.lost_thrum_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.second_succeeded_thrum_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.second_lost_thrum_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.succeeded_thrum_ratio_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.second_succeeded_thrum_ratio_layout).setVisibility(View.VISIBLE);

            tv_spinning_cop_number.setText("0");
            tv_succeeded_thrum_number.setText("0");
            tv_lost_thrum_number.setText("0");
            tv_second_succeeded_thrum_number.setText("0");
            tv_second_lost_thrum_number.setText("0");
            tv_remnant_tube_number.setText("0");
            tv_empty_tube_number.setText("0");
            tv_succeeded_thrum_ratio.setText("0");
            tv_second_succeeded_thrum_ratio.setText("0");
            tv_remnant_tube_ratio.setText("0");
            tv_empty_tube_ratio.setText("0");
        } else if (machine_type.equals("5") || machine_type.equals("2")) {
            findViewById(R.id.in_spindle_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint1_pass_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint1_succeed_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint1_succeed_ratio_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.pull_tube_pass_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint2_pass_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint2_succeed_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint2_succeed_ratio_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint3_pass_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint3_succeed_num_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.joint3_succeed_ratio_layout).setVisibility(View.VISIBLE);

            if (spinningin_type.equals("1")) {
                findViewById(R.id.joint3_pass_num_layout).setVisibility(View.GONE);
                findViewById(R.id.joint3_succeed_num_layout).setVisibility(View.GONE);
                findViewById(R.id.joint3_succeed_ratio_layout).setVisibility(View.GONE);
            } else {
                findViewById(R.id.joint3_pass_num_layout).setVisibility(View.VISIBLE);
                findViewById(R.id.joint3_succeed_num_layout).setVisibility(View.VISIBLE);
                findViewById(R.id.joint3_succeed_ratio_layout).setVisibility(View.VISIBLE);
            }

            findViewById(R.id.succeeded_thrum_num_layout).setVisibility(View.GONE);
            findViewById(R.id.lost_thrum_num_layout).setVisibility(View.GONE);
            findViewById(R.id.second_succeeded_thrum_num_layout).setVisibility(View.GONE);
            findViewById(R.id.second_lost_thrum_num_layout).setVisibility(View.GONE);
            findViewById(R.id.succeeded_thrum_ratio_layout).setVisibility(View.GONE);
            findViewById(R.id.second_succeeded_thrum_ratio_layout).setVisibility(View.GONE);
        }

        if (machine_type.equals("3")) {// 细络联

            tv_spinning_cop_number.setText(String.valueOf(shiftData.enterTubeCountX));// 进管数量
            tv_succeeded_thrum_number.setText(String.valueOf(shiftData.channel1SucceedCountX));// 一通道生头成功数
            tv_lost_thrum_number.setText(String.valueOf(shiftData.channel1FailedCountX));// 一通道生头不成功数
            tv_second_succeeded_thrum_number.setText(String.valueOf(shiftData.channel2SucceedCountX));// 二通道生头成功数
            tv_second_lost_thrum_number.setText(String.valueOf(shiftData.channel2FailedCountX));// 二通道生头不成功数
            tv_remnant_tube_number.setText(String.valueOf(shiftData.remnantTubeCountX));// 残纱管数
            tv_empty_tube_number.setText(String.valueOf(shiftData.emptyTubeCountX));// 空管回送数
            tv_succeeded_thrum_ratio.setText(Report.round(String.valueOf(shiftData.channel1SucceedRatioX), 1));// 一通道生头成功率
            tv_second_succeeded_thrum_ratio.setText(Report.round(String.valueOf(shiftData.channel2SucceedRatioX), 1));// 二通道生头成功率
            tv_remnant_tube_ratio.setText(Report.round(String.valueOf(shiftData.remnantTubeRatioX), 2));// 残纱率
            tv_empty_tube_ratio.setText(Report.round(String.valueOf(shiftData.emptyTubeRatioX), 2));// 空管率
        } else if (machine_type.equals("5")) {// 大纱库:5号栈
            tv_spinning_cop_number.setText(String.valueOf(shiftData.enterTubeCountD));// 进管数量
            tv_in_spindle_number.setText(String.valueOf(shiftData.enterSpindleCountD));// 进入单锭数
            tv_empty_tube_ratio.setText(Report.round(String.valueOf(shiftData.emptyTubeRatioD), 2));// 空管率
            tv_joint1_pass_number.setText(String.valueOf(shiftData.joint1PassCountD));
            tv_joint1_succeed_number.setText(String.valueOf(shiftData.joint1SucceedCountD));
            tv_joint1_succeed_ratio.setText(Report.round(String.valueOf(shiftData.joint1SucceedRatioD), 1));
            tv_pull_tube_pass_number.setText(String.valueOf(shiftData.pullTubeCount));// 拔管处通过数
            tv_remnant_tube_number.setText(String.valueOf(shiftData.remnantTubeCountD));// 残纱管数
            tv_empty_tube_number.setText(String.valueOf(shiftData.emptyTubeCountD));// 空管回送数
            tv_remnant_tube_ratio.setText(Report.round(String.valueOf(shiftData.remnantTubeRatioD), 2));// 残纱率
            tv_joint2_pass_number.setText(String.valueOf(shiftData.joint2PassCountD));
            tv_joint2_succeed_number.setText(String.valueOf(shiftData.joint2SucceedCountD));
            tv_joint2_succeed_ratio.setText(Report.round(String.valueOf(shiftData.joint2SucceedRatioD), 1));
            tv_joint3_pass_number.setText(String.valueOf(shiftData.joint3PassCountD));
            tv_joint3_succeed_number.setText(String.valueOf(shiftData.joint3SucceedCountD));
            tv_joint3_succeed_ratio.setText(Report.round(String.valueOf(shiftData.joint3SucceedRatioD), 1));
        }
    }

    private void initViews() {
        tv_spinning_cop_number = (TextView) findViewById(R.id.spinning_cop_num_value);
        tv_succeeded_thrum_number = (TextView) findViewById(R.id.succeeded_thrum_num_value);
        tv_lost_thrum_number = (TextView) findViewById(R.id.lost_thrum_num_value);
        tv_second_succeeded_thrum_number = (TextView) findViewById(R.id.second_succeeded_thrum_num_value);
        tv_second_lost_thrum_number = (TextView) findViewById(R.id.second_lost_thrum_num_value);
        tv_succeeded_thrum_ratio = (TextView) findViewById(R.id.succeeded_thrum_ratio_value);
        tv_second_succeeded_thrum_ratio = (TextView) findViewById(R.id.second_succeeded_thrum_ratio_value);
        tv_remnant_tube_number = (TextView) findViewById(R.id.remnant_tube_num_value);
        tv_empty_tube_number = (TextView) findViewById(R.id.empty_tube_num_value);
        tv_remnant_tube_ratio = (TextView) findViewById(R.id.remnant_tube_ratio_value);
        tv_empty_tube_ratio = (TextView) findViewById(R.id.empty_tube_ratio_value);

        tv_in_spindle_number = (TextView) findViewById(R.id.in_spindle_num_value);
        tv_joint1_pass_number = (TextView) findViewById(R.id.joint1_pass_num_value);
        tv_joint1_succeed_number = (TextView) findViewById(R.id.joint1_succeed_num_value);
        tv_joint1_succeed_ratio = (TextView) findViewById(R.id.joint1_succeed_ratio_value);
        tv_pull_tube_pass_number = (TextView) findViewById(R.id.pull_tube_pass_num_value);
        tv_joint2_pass_number = (TextView) findViewById(R.id.joint2_pass_num_value);
        tv_joint2_succeed_number = (TextView) findViewById(R.id.joint2_succeed_num_value);
        tv_joint2_succeed_ratio = (TextView) findViewById(R.id.joint2_succeed_ratio_value);
        tv_joint3_pass_number = (TextView) findViewById(R.id.joint3_pass_num_value);
        tv_joint3_succeed_number = (TextView) findViewById(R.id.joint3_succeed_num_value);
        tv_joint3_succeed_ratio = (TextView) findViewById(R.id.joint3_succeed_ratio_value);
    }
}
